package com.blogSystem.information.controller;

import com.blogSystem.information.pojo.Information;
import com.blogSystem.information.service.InformationService;
import entity.Result;
import entity.StatusCode;
import io.jsonwebtoken.Claims;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import util.JwtUtil;

import javax.servlet.http.HttpServletRequest;

@RestController
@CrossOrigin
@RequestMapping("/information")
public class InformationController {

    @Autowired
    private HttpServletRequest request;

    @Autowired
    private InformationService informationService;

    @Autowired
    private JwtUtil jwtUtil;


    @RequestMapping(value = "/",method = RequestMethod.GET)
    public Result information(){
        String token = (String) request.getAttribute("token");
        Claims claims = jwtUtil.parseJWT(token);
        if (token == null || "".equals(token)) {

            return new Result(true, StatusCode.LOGINERROR, "用户未登录！");
        }
else{
            String user_id = claims.getId();
            Information information=informationService.select(user_id);
            return new Result(true,StatusCode.OK,"查询成功！",information);


        }

    }

    //85220877
}
